package com.hyx.api.controller.pc_admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hyx.api.domain.bo.RefundOrderBo;
import com.hyx.api.domain.vo.RefundOrderVo;
import com.hyx.api.service.pc_admin.IRefundOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 退单记录Controller
 *
 * @author ruoyi
 * @date 2023-10-21
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/refund/order")
public class RefundOrderController extends BaseController
{
    private final IRefundOrderService refundOrderService;

    /**
     * 查询退单记录列表
     */
    @PreAuthorize("@ss.hasPermi('refund:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(RefundOrderBo bo)
    {
        startPage();
        List<RefundOrderVo> list = refundOrderService.selectRefundOrderList(bo);
        return getDataTable(list);
    }

    /**
     * 导出退单记录列表
     */
    @PreAuthorize("@ss.hasPermi('refund:order:export')")
    @Log(title = "退单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RefundOrderBo bo)
    {
        List<RefundOrderVo> list = refundOrderService.selectRefundOrderList(bo);
        ExcelUtil<RefundOrderVo> util = new ExcelUtil<>(RefundOrderVo.class);
        util.exportExcel(response, list, "退单记录数据");
    }

    /**
     * 获取退单记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('refund:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(refundOrderService.selectRefundOrderById(id));
    }

    /**
     * 新增退单记录
     */
    @PreAuthorize("@ss.hasPermi('refund:order:add')")
    @Log(title = "退单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody RefundOrderBo bo)
    {
        return toAjax(refundOrderService.insertRefundOrder(bo));
    }

    /**
     * 修改退单记录
     */
    @PreAuthorize("@ss.hasPermi('refund:order:edit')")
    @Log(title = "退单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody RefundOrderBo bo)
    {
        return toAjax(refundOrderService.updateRefundOrder(bo));
    }

    /**
     * 删除退单记录
     */
    @PreAuthorize("@ss.hasPermi('refund:order:remove')")
    @Log(title = "退单记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(refundOrderService.deleteRefundOrderByIds(ids));
    }
}

